package com.alliky.cart.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alliky.cart.BR;
import com.alliky.cart.R;
import com.alliky.cart.databinding.FragmentCartBinding;
import com.alliky.cart.ui.viewmodel.CartViewModel;
import com.alliky.core.base.BaseFragment;
import com.alliky.core.router.RoutePath;

@Route(path = RoutePath.Cart.FRAGMENT_CART)
public class CartFragment extends BaseFragment<FragmentCartBinding, CartViewModel> {

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_cart;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        //通过binding拿到toolbar控件, 设置给Activity
        ((AppCompatActivity) getActivity()).setSupportActionBar(binding.include.toolbar);
        //初始化标题
        mViewModel.initToolbar();

        mViewModel.initData();
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        mViewModel.uc.finishRefresh.observe(this, o -> binding.refreshLayout.finishRefresh());

        mViewModel.uc.finishLoadMore.observe(this, o -> binding.refreshLayout.finishLoadMore());
    }
}
